/* soft_timer.c/h  3.0 */

#ifndef _SOFT_TIMER_H
#define _SOFT_TIMER_H

#include "main.h"

#define TIME_BASE_MS 1 //1ms
#define TIMER_NUM 10
typedef void callback(void *argv, uint16_t argc);
typedef struct softTimer {
	uint8_t state;
	uint8_t mode;
	uint32_t match;
	uint32_t period;
	callback *cb;
	void *argv;
	uint16_t argc;
} softTimer;

typedef enum tmrState {
	SOFT_TIMER_STOPPED = 0, SOFT_TIMER_RUNNING, SOFT_TIMER_TIMEOUT
} tmrState;

typedef enum tmrMode {
	MODE_ONE_SHOT = 0, MODE_PERIODIC,
} tmrMode;

void tickCnt_Update(void);
uint32_t tickCnt_Get(void);
void softTimer_Init(void);
uint8_t softTimer_GetState(uint16_t id);
void softTimer_Start(uint16_t id, tmrMode mode, uint32_t delay, callback *cb, void *argv, uint16_t argc);
void softTimer_Stop(uint16_t id);
void softTimer_Update(void);

#define TIMER0	0
#define TIMER1	1
#define TIMER2	2
#define TIMER3	3

void TIM0_CB(void *argv, uint16_t argc);
void TIM1_CB(void *argv, uint16_t argc);
void TIM2_CB(void *argv, uint16_t argc);
void TIM3_CB(void *argv, uint16_t argc);

#endif
